package com.eascs.workflow.sequence.dao.impl;

import org.springframework.stereotype.Repository;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.workflow.common.dao.BaseDao;
import com.eascs.workflow.common.entity.sequence.SequenceEntity;
import com.eascs.workflow.sequence.dao.SequenceDao;

@Repository
public class SequenceDaoImpl extends BaseDao implements SequenceDao{
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	@Override
	public int insert(SequenceEntity sequenceEntity) {
		try {
			return super.workflowJdbcSession.insert(sequenceEntity);
		} catch (Exception e) {
			logger.error("序列号插入失败,e:",e);
			return 0;
		}
	}

	@Override
	public int udpate(SequenceEntity sequenceEntity) {
		String sql="UPDATE base_sequence SET sequence=sequence+1 WHERE sid =? AND sequence=?";
		return super.workflowJdbcSession.execute(sql, new Object[]{sequenceEntity.getSid(),sequenceEntity.getSequence()});
	}

	@Override
	public SequenceEntity querySequences(String type, String prefix) {
		String sql="SELECT * FROM base_sequence WHERE seq_type=? AND seq_prefix=?";
		return super.findEntity(sql, SequenceEntity.class, new Object[]{type,prefix});
	}

}
